package com.kenyi.co.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {
	/**
	 * 判断字符串是否为空
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str) {
		if ("null".equals(str) ||"".equals(str) || null == str) {
			return false;
		}
		return true;
	}
	/**
	 * 判断字符串是否为空
	 *
	 * @param str
	 * @return
	 */
	public static boolean isNotEmptypro(String str) {
		if ("null".equals(str) ||"".equals(str) || null == str) {
			return false;
		}
		return true;
	}



	public static String publicStringSubstring(String content, int L) {

		if (isNotEmpty(content)) {
			if (content.length() >= L) {
				content = content.substring(0, L).trim();
				return content;
			} else {
				return content;
			}
		}
		return content;
	}

	public static boolean replayStringLength(String content) {
		if (isNotEmpty(content)) {
			if (content.length() >= 5) {
				return true;
			} else {
				return false;
			}
		}
		return false;
	}

	/**
	 * 计算位数
	 * 
	 * @param str
	 * @return
	 */
	public static int calculatePlaces(String str) {
		int m = 0;
		char arr[] = str.toCharArray();
		for (int i = 0; i < arr.length; i++) {
			char c = arr[i];
			if ((c >= 0x0391 && c <= 0xFFE5)) // 中文字符
			{
				m = m + 2;
			} else if ((c >= 0x0000 && c <= 0x00FF)) // 英文字符
			{
				m = m + 1;
			}
		}
		return m;
	}

	public static boolean isMobileNum(String mobiles) {
		Pattern p = Pattern.compile("^(1[0-9])\\d{9}$");
		Matcher matcher = p.matcher(mobiles);
		return matcher.matches();
	}

}
